<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>CTF题目管理</title>
	<meta name="decorator" content="default"/>
	<script src="${path}/js/common/jquery.form.js"></script>

	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		$(function () {
			$("#attachmentUpload").click(function () {
				$.jBox($("#importBox").html(), {
					title: "上传附件", buttons: {"关闭": true},
//					bottomText: "上传文件不能超过10M，仅允许上传“jar”格式文件！",
					loaded: function (e) {
						e.find(".btnImportSubmit").click(function () {
							if (e.find("#uploadFile").val() == "") {
								alertx("请选择附件上传");
								return false;
							}
							e.find("#importForm").ajaxSubmit({
								type: "POST",
								dataType: "json",
								url: "${ctx}/resource/resourceCtfSubject/attachmentUpload",
								success: function (json) {
									if (json.success == true) {
										var fileList = json.dataObj;
										$("#attachmentId").val(fileList[0]);
										$("#attachment").val(fileList[1]);
										alertx("上传成功");
//                                        console.debug( e.parent().next().children("button"));
										e.parent().next().children("button").click();
									}
									else {
										window.location.href = "${ctx}/resource/resourceCtfSubject/form";
									}
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									alert(errorThrown);
								}
							});

						})
					}

				});
			});
		});
		$(function () {
			$("#solutionUpload").click(function () {
				$.jBox($("#solutionImportBox").html(), {
					title: "上传解题思路", buttons: {"关闭": true},
					bottomText: "仅允许上传“pdf”格式文件！",
					loaded: function (e) {
						e.find(".btnSolutionImportSubmit").click(function () {
							if (e.find("#solutionUploadFile").val() == "") {
								alertx("请选择上传解题思路pdf文件");
								return false;
							}
							e.find("#solutionImportForm").ajaxSubmit({
								type: "POST",
								dataType: "json",
								url: "${ctx}/resource/resourceCtfSubject/solutionUpload",
								success: function (json) {
									if (json.success == true) {
										var fileList = json.dataObj;
										$("#solutionId").val(fileList[0]);
										$("#solution").val(fileList[1]);
										alertx("上传成功");
//                                        console.debug( e.parent().next().children("button"));
										e.parent().next().children("button").click();
									}
									else {
										window.location.href = "${ctx}/resource/resourceCtfSubject/form";
									}
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									alertx(errorThrown);
								}
							});

						})
					}

				});
			});
		});
		function checkValidate()
		{
			var ctfSubjectTypeId=document.getElementById("ctfSubjectTypeId").value;
			//判断是否为空
			if(ctfSubjectTypeId==""||ctfSubjectTypeId==null)
			{
				window.alertx("请选择题目类型！");
				return false;
			}
		}
		function picCheck(selector) {

			var fileName = $(selector).val();

			if (fileName != null && fileName != "") {
				var fileExt = fileName.substr(fileName.lastIndexOf(".")).toLowerCase();
				var supportFile = new Array(".pdf");

				//lastIndexOf如果没有搜索到则返回为-1
				if ($.inArray(fileExt, supportFile) == -1) {
					var file = $(selector);
					file.after(file.clone().val(""));
					file.remove();
					alertx("文件类型不合法，只能是pdf格式");
				}
			}
		}
	</script>
</head>
<body>
<div id="importBox" class="hide">
	<form id="importForm" enctype="multipart/form-data"
		  class="form-search" style="padding-left:20px;text-align:center;"><br/>
		<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
		<button type="button" class="btn btn-primary btnImportSubmit"> 上 传</button>
	</form>
</div>

<div id="solutionImportBox" class="hide">
	<form id="solutionImportForm" enctype="multipart/form-data"
		  class="form-search" style="padding-left:20px;text-align:center;"><br/>
		<input id="solutionUploadFile" name="solutionUploadFile" type="file" style="width:330px" onchange="picCheck(this)"/><br/><br/>　　
		<button type="button" class="btn btn-primary btnSolutionImportSubmit"> 上 传</button>
	</form>
</div>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/resource/resourceCtfSubject/">CTF题目列表</a></li>
		<li class="active"><a href="${ctx}/resource/resourceCtfSubject/detail?id=${resourceCtfSubject.id}">CTF题目详情 </a></li>
		<li><a href="${ctx}/resource/resourceCtfSubject/subjectTypeList">题目类型管理</a></li>

	</ul><br/>

	<form:form id="inputForm" modelAttribute="resourceCtfSubject" action="" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">CTF题目名称：</label>
			<div class="controls">
				<form:input path="ctfSubjectName" htmlEscape="false" maxlength="64" class="input-xlarge required" readonly="true"/>
				<%--<input  type="text" id="isSuperAdmin" value="${isSuperAdmin}" maxlength="64" class="input-xlarge required"/>--%>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">题目属性：</label>
			<div class="controls">
				<%--<form:select path="ctfSubjectAttribute" class="input-xlarge required">--%>
					<%--<form:option value="" label=""/>--%>
					<%--<form:options items="${fns:getDictList('resource_question_attribute')}" itemLabel="label" itemValue="value" htmlEscape="false"/>--%>
				<%--</form:select>--%>
				<select id="ctfSubjectAttribute" name="ctfSubjectAttribute" class="input-xlarge required" onfocus="<c:if test="${isSuperAdmin=='no'}">this.defaultIndex=this.selectedIndex;</c:if>" onchange="<c:if test="${isSuperAdmin=='no'}">this.selectedIndex=this.defaultIndex;</c:if>" readOnly="<c:if test="${isSuperAdmin=='no'}">true</c:if>">
					<c:forEach var="attribute" items="${fns:getDictList('resource_question_attribute')}">
						<option value="${fns:getDictValue(attribute,'resource_question_attribute',"")}" <c:if test="${fns:getDictValue(attribute,'resource_question_attribute','')==resourceCtfSubject.ctfSubjectAttribute}">selected</c:if>>${attribute}</option>
					</c:forEach>
				</select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">标签：</label>
			<div class="controls">
				<form:input path="label" htmlEscape="false" maxlength="64" class="input-xlarge " readonly="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">题目类型：</label>
			<div class="controls">

				<form:input path="ctfSubjectTypeId" htmlEscape="false" maxlength="64" class="input-xlarge required" readonly="true"/>
				<%--<select id="ctfSubjectTypeId" name="ctfSubjectTypeId" class="input-xlarge" disabled="true">--%>
					<%--<option value="" label="" selected>===请选择===</option>--%>
					<%--<c:forEach items="${ctfSubjectTypeList}" var="ctfSubjectType">--%>
						<%--<option value="${ctfSubjectType.id}" <c:if test="${ctfSubjectType.id==resourceCtfSubject.ctfSubjectTypeId}">selected</c:if>>${ctfSubjectType.subjectTypeName}</option>--%>
					<%--</c:forEach>--%>
				<%--</select>--%>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">题干：</label>
			<div class="controls">
				<form:textarea path="stem" htmlEscape="false" rows="4" class="input-xxlarge " readonly="true" />
				<sys:ckeditor replace="stem" uploadPath="/itemDescribe" />

			</div>
		</div>

		<div class="control-group">
			<label class="control-label">附件：</label>
			<div class="controls">
				<input type="hidden" name="attachmentId" id="attachmentId" htmlEscape="false" maxlength="256" class="input-xlarge" value="${resourceCtfSubject.attachment}" readonly="true"/>
				<input type="text" name="attachment" id="attachment" htmlEscape="false" maxlength="256" class="input-xlarge" value="${resourceCtfSubject.attachment}" readonly="true"/>
				<input id="attachmentUpload" class="btn btn-primary" type="button" value="上传"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">题目难度：</label>
			<div class="controls">
				<form:select path="questionDifficulty" class="input-xlarge required" disabled="true">
					<%--<form:option value="" label=""/>--%>
					<form:options items="${fns:getDictList('resource_question_difficulty')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">分值：</label>
			<div class="controls">
				<form:input path="score" htmlEscape="false" maxlength="8" class="input-xlarge required" readonly="true"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">题目答案：</label>
			<div class="controls">
				<form:input path="answer" htmlEscape="false" maxlength="255" class="input-xlarge " readonly="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">关联实验环境：</label>
			<div class="controls">
				<select id="ctfEnvironmentId" name="ctfEnvironmentId" class="input-xlarge" disabled="true">
					<option value="" selected>无</option>
					<c:forEach items="${sceneEnvironmentList}" var="sceneEnvironment">
						<option value="${sceneEnvironment.id}" <c:if test="${sceneEnvironment.id==resourceCtfSubject.ctfEnvironmentId}"> selected</c:if>>${sceneEnvironment.environmentName}</option>
					</c:forEach>
				</select>

			</div>
		</div>
		<div class="control-group">
			<label class="control-label">基本提示：</label>
			<div class="controls">
				<form:textarea path="tip" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge " readonly="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">解题思路：</label>
			<div class="controls">
				<%--<form:textarea path="solution" htmlEscape="false" rows="4" maxlength="128" class="input-xxlarge "/>--%>
				<input type="hidden" name="solutionId" id="solutionId" htmlEscape="false" maxlength="256" class="input-xlarge" value="${resourceCtfSubject.attachment}" readonly="true"/>
				<input type="text" name="solution" id="solution" htmlEscape="false" maxlength="256" class="input-xlarge" value="${resourceCtfSubject.attachment}" readonly="true"/>
				<input id="solutionUpload" class="btn btn-primary" type="button" value="上传"/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="resource:resourceCtfSubject:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存" onclick="return checkValidate()"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>